﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kokomo.Mirror.Ia32
{
	public class Ia32eOpCodeLookup : IaOpCodeLookup
	{
		static Ia32eOpCodeLookup()
		{
			Instance = new Ia32eOpCodeLookup();
		}

		public static Ia32eOpCodeLookup Instance { get; private set; }

		private Ia32eOpCodeLookup()
		{
		}

		protected override void DefinePrefixes(IDictionary<int, Prefixes> prefixTable)
		{
			base.DefinePrefixes(prefixTable);

			for (int i = 0; i < 0x10; i++)
			{
				prefixTable[0x40 + i] = (Prefixes)(i << (int)Prefixes.RexShift);
			}
		}

		protected override void DefineSimpleOpCodes(List<OpCode> opCodes)
		{
			base.DefineSimpleOpCodes(opCodes);

			opCodes.AddRange(new OpCode[] {
				// 5x
				new OpCode(0x50, 1, OpCodeForm.RegCode, Mnemonic.push, OperandType.GeneralPurposeRegister | OperandType.OpCodeReg | OperandType.Qword),
				new OpCode(0x58, 1, OpCodeForm.RegCode, Mnemonic.pop, OperandType.GeneralPurposeRegister | OperandType.OpCodeReg | OperandType.Qword),
				// 6x
				//new OpCode(0x63, 1, OpCodeForm.ModRM, Mnemonic.movsxd, OperandType.Gv, OperandType.Ev),
				new OpCode(0x68, 1, OpCodeForm.Normal, Mnemonic.push, OperandType.Iq),
				new OpCode(0x6A, 1, OpCodeForm.Normal, Mnemonic.push, OperandType.Ib),
			});
		}
	}
}
